From 9344719772d0fb4c849740269e6d226588822b93 Mon Sep 17 00:00:00 2001 From: robertl Date: Wed, 14 Mar 2007 17:34:11 +0000 Subject: [PATCH] Jon McClintlock and Robert Lipe fix bogus free in Linux/Mac USB garmin teardown. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@2702 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/jeeps/gpslibusb.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/gpsbabel/jeeps/gpslibusb.c b/gpsbabel/jeeps/gpslibusb.c index 42dd63e86..efc84db73 100644 --- a/gpsbabel/jeeps/gpslibusb.c +++ b/gpsbabel/jeeps/gpslibusb.c @@ -104,12 +104,25 @@ gusb_teardown(gpsdevh *dh) if (udev) { usb_release_interface(udev, 0); usb_close(udev); - xfree(dh); + /* In the worst case, we leak a little bit of memory + * when called via the atexit handler. That's not too + * terrible. + */ + if (NULL != dh) { + xfree(dh); + } udev = NULL; } return 0; } +static void +gusb_atexit_teardown(void) +{ + gusb_teardown(NULL); +} + + /* * This is a function of great joy to discover. * @@ -200,7 +213,7 @@ garmin_usb_start(struct usb_device *dev) if (udev) return; udev = usb_open(dev); - atexit((void(*)())gusb_teardown); + atexit(gusb_atexit_teardown); if (!udev) { fatal("usb_open failed: %s\n", usb_strerror()); } /* -- 2.30.2